/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cronus.client;

import java.io.*;
import java.net.*;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.fdsapi.ResultSetUtils;

/**
 *
 * @author Jannick
 */
public class SocketConnection {
    //Attributen
    private InetAddress host;
    private Socket socket;
    private String query;
    //Constructor
    public SocketConnection(){
        try {
            host = InetAddress.getLocalHost();
            socket = new Socket(host.getHostName(), 4444);
            
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        } catch (IOException ex){
            ex.printStackTrace();
        }
    }
    
    //Methodes
    public void send(String query){
        this.query = query;
        try {
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(query);
        } catch ( IOException ex ){
            ex.printStackTrace();
        }
    }
    
    public Object[][] read(){
        Object[][] result = null;
        try{
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            result = (Object[][]) ois.readObject();
            
        } catch ( IOException ex ){
            ex.printStackTrace();
        } catch (ClassNotFoundException ex){
            ex.printStackTrace();
        }
        
        return result;
    
    }
    
}
